<template>
  <div>
    <!-- 整个容器 -->
    <el-container>
      <!-- 上半部分：顶栏 -->
      <el-header class="layout-header">
        <div class="login-user">
          <span class="welcome">欢迎回来, root! </span>
          <el-dropdown>
            <el-avatar size="small" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"></el-avatar>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item icon="el-icon-s-finance">修改资料</el-dropdown-item>
              <el-dropdown-item icon="el-icon-s-custom">修改头像</el-dropdown-item>
              <el-dropdown-item icon="el-icon-s-cooperation">修改密码</el-dropdown-item>
              <el-dropdown-item icon="el-icon-remove" divided>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <h1>酷鲨商城管理系统</h1>
      </el-header>
      <!-- 下半部分 -->
      <el-container class="layout-body">
        <!-- 下半部分的左侧：侧边栏 -->
        <el-aside class="layout-aside">
          <el-menu
              router
              :default-active="activeMenuItemPath"
              class="el-menu-vertical-demo"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#fff">
            <!-- 首页 -->
            <el-menu-item index="1">
              <i class="el-icon-s-home"></i><span>首页</span>
            </el-menu-item>
            <!-- 商品管理 -->
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-s-goods"></i><span>商品管理</span>
              </template>
              <el-menu-item index="/sys-admin/product/spu-management">
                <i class="el-icon-s-grid"></i><span>SPU台账</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/spu/add-new-1">
                <i class="el-icon-circle-plus"></i><span>新增SPU</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/album">
                <i class="el-icon-picture"></i><span>相册管理</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/category">
                <i class="el-icon-s-unfold"></i><span>商品类别</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/attribute-template">
                <i class="el-icon-s-flag"></i><span>属性模板</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/attribute">
                <i class="el-icon-s-ticket"></i><span>属性管理</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/brand">
                <i class="el-icon-s-data"></i><span>品牌管理</span>
              </el-menu-item>
            </el-submenu>
            <!-- 订单管理 -->
            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-order"></i><span>订单管理</span>
              </template>
              <el-menu-item index="3-1" disabled>
                <i class="el-icon-error"></i><span>暂无内容</span>
              </el-menu-item>
            </el-submenu>
            <!-- 营销管理 -->
            <el-submenu index="4">
              <template slot="title">
                <i class="el-icon-s-management"></i><span>营销管理</span>
              </template>
              <el-menu-item index="4-1" disabled>
                <i class="el-icon-error"></i><span>暂无内容</span>
              </el-menu-item>
            </el-submenu>
            <!-- 商家管理 -->
            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-s-shop"></i><span>商家管理</span>
              </template>
              <el-menu-item index="5-1" disabled>
                <i class="el-icon-error"></i><span>暂无内容</span>
              </el-menu-item>
            </el-submenu>
            <!-- 权限管理 -->
            <el-submenu index="6">
              <template slot="title">
                <i class="el-icon-s-check"></i><span>权限管理</span>
              </template>
              <el-menu-item index="/sys-admin/permission/admin">
                <i class="el-icon-s-custom"></i><span>管理员管理</span>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!-- 下半部分的右侧：主体 -->
        <el-main class="layout-main">
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activeMenuItemPath: ''
    };
  },
  methods: {
    handleActiveMenuItemPath(){
      let currentPath = this.$router.currentRoute.path;
      if(currentPath.startsWith('/sys-admin/product/album')){
        currentPath = '/sys-admin/product/album';
      }else if(currentPath.startsWith('/sys-admin/product/category')){
        currentPath = '/sys-admin/product/category';
      }else if(currentPath.startsWith('/sys-admin/product/attribute-template')){
        currentPath = '/sys-admin/product/attribute-template';
      }else if(currentPath.startsWith('/sys-admin/product/brand')){
        currentPath = '/sys-admin/product/brand';
      }else if(currentPath.startsWith('/sys-admin/permission/admin')){
        currentPath = '/sys-admin/permission/admin';
      }else if(currentPath.startsWith('/sys-admin/product/spu/add')){
        currentPath = '/sys-admin/product/spu/add-new-1';
      }else if(currentPath.startsWith('/sys-admin/product/attribute')){
        currentPath = '/sys-admin/product/attribute';
      }else if(currentPath.startsWith('/sys-admin/product/spu-management')){
        currentPath = '/sys-admin/product/spu-management';
      }

      this.activeMenuItemPath = currentPath;
    }
  },
  mounted() {
    this.handleActiveMenuItemPath();
  }
}
</script>

<style>

.layout-header {
  background: #2c3e50;
}

.layout-header h1 {
  line-height: 60px;
  color: #fff;
}

.layout-header .login-user {
  float: right;
  display: flex;
  margin-top: 16px;
}

.layout-header .login-user .welcome {
  line-height: 28px;
  color: #fff;
  margin-right: 20px;
}


.layout-body {
  position: absolute;
  top: 60px;
  bottom: 0;
  left: 0;
  right: 0;
}

.layout-aside {
  background-color: #545c64;
}

.layout-aside i {
  color: #fff !important;
}

.layout-aside .el-menu-item.is-active {
  background: #2c3e50 !important;
}

.layout-aside .el-menu {
  border: 0;
}

.layout-main {
  background-color: #fff;
}
</style>





